package com.xuyiwei.mayi.test;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by xuyiwei on 2019/4/13.
 */
public class TCPServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        while (true){
            Socket socket = serverSocket.accept();
            InputStream in = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int len = -1;
            StringBuffer sb = new StringBuffer();
            while ((len=(in.read(bytes)))!=-1){
                sb.append(new String(bytes,0,len));
            }
            System.out.println(sb.toString());
        }
    }
}
